using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Entry : MonoBehaviour
{
    // Start is called before the first frame update
    IEnumerator Start()
    {
        yield return InitLoadPanel();
        yield return InitAssetBundle();
        yield return InitDataTables();
        yield return InitMain();
        yield return InitUIBundle();
        yield return InitPoolBundle();
        yield return InitSound();
        Debug.Log("Init Finish");
        yield return InitLoadSaveData();
        SceneManager.Instance.LoadScene<MainUISceneMgr>("CommonScene");
    }

    List<string> filesTable;
    List<string> bundlTable;
    ResourceLoadPanel resLoadPanel;
    IEnumerator InitSound()
    {
        yield return null;
        AssetBundleManager abmgr = AssetBundleManager.Instance;
        SoundManager.Instance.SetBundle(abmgr.bundles[abmgr.SOUND_BUNDLE]);

    }
    IEnumerator InitLoadPanel()
    {
        yield return null;
        resLoadPanel = UIManager.Instance.InitPlane<ResourceLoadPanel>(0, CanvasType.Front, null, true);
        resLoadPanel.Open(Vector3.zero, Vector3.one);
    }
    IEnumerator InitDataTables()
    {
        AssetBundleManager abmgr = AssetBundleManager.Instance;
        filesTable = new List<string>();
        filesTable.Add("TestConfigTable.txt");
        yield return abmgr.DownloadTables(filesTable.ToArray());
        TableDataMgr.Instance.Init();
    }
    IEnumerator InitUIBundle()
    {
        yield return null;
        AssetBundleManager abmgr = AssetBundleManager.Instance;
        UIManager.Instance.SetUIBundle(abmgr.bundles[abmgr.UI_BUNDLE]);
    }
    IEnumerator InitPoolBundle()
    {
        yield return null;
        AssetBundleManager abmgr = AssetBundleManager.Instance;
        ObjectPoolManager.Instance.InitBundles(null, abmgr.bundles);
    }
    IEnumerator InitMain()
    {
        MainMgr main = MainMgr.Instance;
        yield return null;
    }   

    IEnumerator InitLoadSaveData()
    {   
        Debug.Log("Init Load Save Data");
        yield return null;
        //MainMgr.Instance.InitSaveData();
        yield return MainMgr.Instance.LoadPlayerSettingData();
        Debug.Log("Load Save Data Finish"  );
    }
    IEnumerator InitAssetBundle()
    {
        AssetBundleManager abmgr = AssetBundleManager.Instance;
        abmgr.Init();
        bundlTable = new List<string>();
        resLoadPanel.SetPorcess(25);
        bundlTable.Add(abmgr.UI_BUNDLE);
        //bundlTable.Add(abmgr.POOL_BUNDLE);
        bundlTable.Add(abmgr.SCENE_BUNDLE);
        bundlTable.Add(abmgr.SOUND_BUNDLE);

        bundlTable.Add("Prefab_ARPG");
        bundlTable.Add("Prefab_Common");
        bundlTable.Add("Prefab_UINode");
        bundlTable.Add("Prefab_UINode");

        yield return abmgr.DownloadBundles(bundlTable.ToArray());


        resLoadPanel.SetPorcess(25);
    }

}
